import strformat
type
  Clock* = tuple[hour, min: int]

const MinutesPerDay = 24 * 60

proc create*(clock: (int, int)): Clock = 
  var
    (h, m) = clock
    all = (h * 60 + m) mod MinutesPerDay
  if all < 0:
    all.inc MinutesPerDay
  (hour: all div 60, min: all mod 60)

proc toStr*(clock: Clock): string =
  fmt"{clock.hour:02}:{clock.min:02}"

proc add*(clock: (int, int), n: int): Clock = 
  create((clock[0], clock[1] + n))

proc subtract*(clock: (int, int), n: int): Clock = 
  create((clock[0], clock[1] - n))
